package com.xingkeduo.utils;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author chi  2019-01-24 17:23
 **/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Slf4j
public class ResponseTransterUtils<T> {

    /**
     * 存储错误信息
     */

    private T content;


    private int error;

    private String reason;


    public static <T> ResponseTransterUtils getSuccess(T content) {
        ResponseTransterUtils<Object> result = ResponseTransterUtils.builder()
                .error(0)
                .reason("0")
                .content(content)
                .build();
        return result;
    }

    public static ResponseTransterUtils getSuccess() {
        return getSuccess(null);
    }


    /**
     * 错误信息
     *
     * @param msg
     * @param code
     * @return
     */
    public static ResponseTransterUtils error(String msg, String code) {
        ResponseTransterUtils<Object> result = ResponseTransterUtils.builder()
                .error(1)
                .reason(msg)
                .build();
        return result;
    }

}

